// MainFrm.h : interface of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_MAINFRM_H__204D5A14_68A4_4F08_B35C_0A7FB6A9D425__INCLUDED_)
#define AFX_MAINFRM_H__204D5A14_68A4_4F08_B35C_0A7FB6A9D425__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "..\public\ComLib\SerialPort.h"
#include "..\public\SocketLib\SocketManager.h"
#include "Globals.h"
#include "DialogZoom.h"
#include "DialogReport.h"

enum ENUM_ECG_OPEN_TYPE{
	ECG_OPEN_TYPE_NONE,
	ECG_OPEN_TYPE_FILE,
	ECG_OPEN_TYPE_COM
};

// typedef enum ECG_PRINT_TYPE{
// 	ECG_PRINT_TYPE_NULL,
// 	ECG_PRINT_TYPE_WAVEFORMH,
// 	ECG_PRINT_TYPE_WAVEFORMV,
// 	ECG_PRINT_TYPE_WAVEFORM31,
// 	ECG_PRINT_TYPE_WAVEFORM61,
// 	ECG_PRINT_TYPE_REPORTH,
// 	ECG_PRINT_TYPE_REPORTH_WAVEFORM,
// 	ECG_PRINT_TYPE_REPORTH_WAVEFORM31,
// 	ECG_PRINT_TYPE_RR
// }ECGPrintType;
#define MAX_CONNECTION		10

#define WM_DISP_PATINFO WM_USER + 1035

class CMainFrame : public CFrameWnd
{
	
protected: // create from serialization only
	CMainFrame();
	DECLARE_DYNCREATE(CMainFrame)

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMainFrame)
	public:
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	protected:
	virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CMainFrame();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:  // control bar embedded members
	CStatusBar  m_wndStatusBar;
	CToolBar    m_wndToolBar;

// Generated message map functions
protected:
	//{{AFX_MSG(CMainFrame)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnToolbarPrint();
	afx_msg void OnUpdateToolbarPrint(CCmdUI* pCmdUI);
	afx_msg void OnMenuRestore();
	afx_msg void OnUpdateMenuRestore(CCmdUI* pCmdUI);
	afx_msg void OnMenuLogin();
	afx_msg void OnUpdateMenuLogin(CCmdUI* pCmdUI);
	afx_msg void OnMenuLogout();
	afx_msg void OnUpdateMenuLogout(CCmdUI* pCmdUI);
	afx_msg void OnSystemSetting();
	afx_msg void OnUpdateSystemSetting(CCmdUI* pCmdUI);
	afx_msg void OnMenuUserinfo();
	afx_msg void OnUpdateMenuUserinfo(CCmdUI* pCmdUI);
	afx_msg void OnMenuEditpwd();
	afx_msg void OnUpdateMenuEditpwd(CCmdUI* pCmdUI);
	afx_msg void OnEditAnn();
	afx_msg void OnUpdateEditAnn(CCmdUI* pCmdUI);
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnClose();
	afx_msg void OnUpdateFileSaveAs(CCmdUI* pCmdUI);
	afx_msg void OnLanguageChinese();
	afx_msg void OnUpdateLanguageChinese(CCmdUI* pCmdUI);
	afx_msg void OnLanguageEnglish();
	afx_msg void OnUpdateLanguageEnglish(CCmdUI* pCmdUI);
	afx_msg void OnLanguageRuss();
	afx_msg void OnUpdateLanguageRuss(CCmdUI* pCmdUI);
	afx_msg void OnUpdateFileOpen(CCmdUI* pCmdUI);
	afx_msg void OnUpdateFileSave(CCmdUI* pCmdUI);
	afx_msg void OnToolbarDropDown(NMTOOLBAR* pnmh, LRESULT* plRes);
	afx_msg void OnMenuPrintWaveformh();
	afx_msg void OnUpdateMenuPrintWaveformh(CCmdUI* pCmdUI);
	afx_msg void OnMenuPrintWaveform31();
	afx_msg void OnUpdateMenuPrintWaveform31(CCmdUI* pCmdUI);
	afx_msg void OnMenuPrintWaveformv();
	afx_msg void OnUpdateMenuPrintWaveformv(CCmdUI* pCmdUI);
	afx_msg void OnMenuPrintWaveform61();
	afx_msg void OnUpdateMenuPrintWaveform61(CCmdUI* pCmdUI);
	afx_msg void OnPrintRr();
	afx_msg void OnUpdatePrintRr(CCmdUI* pCmdUI);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnMove(int x, int y);
	afx_msg void OnReportModel();
	afx_msg void OnToolbarPrintprev();
	afx_msg void OnMyFileOpen();
	afx_msg void OnUpdateToolbarPrintprev(CCmdUI* pCmdUI);
	afx_msg void OnToolbarMmms();
	afx_msg void OnUpdateToolbarMmms(CCmdUI* pCmdUI);
	afx_msg void OnToolbarMmmv();
	afx_msg void OnUpdateToolbarMmmv(CCmdUI* pCmdUI);
	afx_msg void OnFileSaveAsJpg();
	afx_msg void OnFileSaveAsBmp();

	afx_msg void OnUpdateFileSaveAsJpg(CCmdUI* pCmdUI);
	afx_msg void OnUpdateFileSaveAsBmp(CCmdUI* pCmdUI);
	afx_msg void OnModelDefault();
	afx_msg void OnUpdateModelDefault(CCmdUI* pCmdUI);
	//}}AFX_MSG
	afx_msg LONG OnCommunication(UINT, LONG);
	afx_msg LONG OnCommunicationBegin(UINT, LONG);
	afx_msg void OnDispPatInfo(WPARAM wParam, LPARAM lParam);
	DECLARE_MESSAGE_MAP()

public:
	ECG_DATA_DEF m_ecgDataDef;
	int m_nReadTime;
	UINT m_uReadTimer;

	CDialogZoom m_dlgZoom;
	int m_ecgPrintType;
	CDialogReport m_dlgReport;




private:
	CSerialPort _SerialPort;
	signed char _cReceiveData[RECEIVE_DATA_SIZE];
	int _nReceivePos;
	BOOL _bCanReceiveData;

	CSocketManager m_SocketManager[MAX_CONNECTION];
	CSocketManager* m_pCurServer;

	CWinThread* m_pSocketThread;
	HANDLE m_hThread;

	BOOL bRunAgain;

	CString m_strReceivePatient;

	CRect _rcViewPrev;


public:
	BOOL IsRRType();
	void SetReceiveStatus(CString strInfo);
	void SetScaleResult(CString strResult);
	BOOL SavePatientNoDlg(ECG_DATA_DEF* ecgDef);
	BOOL SavePatientHaveDlg(ECG_DATA_DEF* ecgDef);
	BOOL BuildPatientInfoFromIS(ECG_DATA_DEF* ecgDef);
	bool StartServer();
//	BOOL BuildECGData(void);
	BOOL CanReceiveData();
	void CanReceiveData(BOOL bCanReceiveData);
	void ClearBufData(void);
	void ProcessECGData(void);
	void AddPatientStudy(ENUM_ECG_OPEN_TYPE nECGOpenType = ECG_OPEN_TYPE_NONE);
	void SendDicomFile(PATIENT_DATA* pPatientData);

	void ClearWaveForm();
	void DockReportDlg();
	//void PatientChanged();
	void PatientChanged(char * pFrame=NULL);
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MAINFRM_H__204D5A14_68A4_4F08_B35C_0A7FB6A9D425__INCLUDED_)
